<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title>注册</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>

    <link rel="stylesheet" href="./AmazeUI-2.4.2/assets/css/amazeui.min.css"/>
    <link href="./css/dlstyle.css" rel="stylesheet" type="text/css">
    <script src="./AmazeUI-2.4.2/assets/js/jquery.min.js"></script>
    <script src="./AmazeUI-2.4.2/assets/js/amazeui.min.js"></script>

    <!--导入vue和axios文件-->
    <script src="./plugins/vue/dist/vue.js"></script>
    <script src="./plugins/axios/dist/axios.js"></script>
    <script src="./js/common.js"></script>
    <style type="text/css">
        .validateMsg {color: red;font-size: 12px;}
    </style>

</head>

<body>
<div id="app">
    <div class="login-boxtitle">
        <a href="home/demo.html"><img alt="" src="./images/logobig.png"/></a>
    </div>

    <div class="res-banner">
        <div class="res-main">
            <div class="login-banner-bg"><span></span><img src="./images/big.jpg"/></div>
            <div class="login-box">

                <!--注册选项卡-->
                <div class="am-tabs" id="doc-my-tabs">
                    <ul class="am-tabs-nav am-nav am-nav-tabs am-nav-justify">
                        <li class="am-active"><a href="">邮箱注册</a></li>
                        <li><a href="">手机号注册</a></li>
                    </ul>

                    <div class="am-tabs-bd">

                        <!--1.邮箱注册-->
                        <div class="am-tab-panel am-active">
                            <form method="post" :model="emailReg">
                                <div class="user-email">
                                    <label for="email_reg"><i class="am-icon-envelope-o"></i></label>
                                    <input type="email" v-model="emailReg.email" @blur="ValidEmail" name="" id="email_reg" placeholder="请输入邮箱账号">
                                    <span class="validateMsg">{{emailValidateMsg}}</span>
                                </div>
                                <div class="user-pass">
                                    <label for="password"><i class="am-icon-lock"></i></label>
                                    <input type="password" v-model="emailReg.password" name="" id="password" placeholder="设置密码">
                                </div>
                                <div class="user-pass">
                                    <label for="passwordRepeat"><i class="am-icon-lock"></i></label>
                                    <input type="password" v-model="emailReg.confirmPassword" name="" id="passwordRepeat" placeholder="确认密码">
                                </div>

                            </form>
                            <div class="login-links">
                                <label for="reader-me_phone">
                                    <input id="reader-me_email" :checked="emailReg.agreement"
                                           @click="emailReg.agreement=!emailReg.agreement"
                                           type="checkbox"> 点击表示您同意商城《服务协议》
                                </label>
                                <span class="validateMsg">{{agreementValidateMsg}}</span>
                            </div>
                            <div class="am-cf">
                                <input type="button" name="" @click="emailSubmit" value="注册" class="am-btn am-btn-primary am-btn-sm am-fl">
                            </div>

                        </div>

                        <!--2.手机验证码注册-->
                        <div class="am-tab-panel">
                            <form method="post" :model="phoneReg"  >
                                <div class="user-phone">
                                    <div>
                                        <label for="phone_reg"><i class="am-icon-mobile-phone am-icon-md"></i></label>
                                        <input type="tel" name="" v-model="phoneReg.phone" @blur="validPhone" id="phone_reg" placeholder="请输入手机号">
                                    </div>
                                    <span class="validateMsg">{{phoneValidateMsg}}</span>
                                </div>
                                <div class="verification">
                                    <label for="code"><i class="am-icon-code-fork"></i></label>
                                    <input type="tel" name="" v-model="phoneReg.verifyCode" id="code" placeholder="请输入验证码">
                                    <button type="button" class="btn" :disabled="btnDisabled" @click="sendMobileCode" id="dyMobileButton" style="margin-bottom: 15px;">
                                        {{btnText}}
                                    </button>
                                </div>
                                <div class="user-pass">
                                    <label for="password_phone"><i class="am-icon-lock"></i></label>
                                    <input type="password" name="" v-model="phoneReg.password" id="password_phone" placeholder="设置密码" required>
                                </div>
                                <div class="user-pass">
                                    <label for="passwordRepeat_phone"><i class="am-icon-lock"></i></label>
                                    <input type="password" name="" v-model="phoneReg.confirmPassword" id="passwordRepeat_phone" placeholder="确认密码">
                                </div>
                            </form>
                            <div class="login-links">
                                <label for="reader-me_phone">
                                    <input id="reader-me_phone" :checked="phoneReg.agreement"
                                           @click="phoneReg.agreement=!phoneReg.agreement"
                                            type="checkbox"> 点击表示您同意商城《服务协议》
                                </label>
                                <span class="validateMsg">{{agreementValidateMsg}}</span>
                            </div>
                            <div class="am-cf">
                                <input type="button" @click="submitReg" name="" value="注册" class="am-btn am-btn-primary am-btn-sm am-fl">
                            </div>

                            <hr>
                        </div>

                    </div>
                </div>

            </div>
        </div>
    </div>

    <div class="footer ">
        <div class="footer-hd ">
            <p>
                <a href="# ">恒望科技</a>
                <b>|</b>
                <a href="# ">商城首页</a>
                <b>|</b>
                <a href="# ">支付宝</a>
                <b>|</b>
                <a href="# ">物流</a>
            </p>
        </div>
        <div class="footer-bd ">
            <p>
                <a href="# ">关于恒望</a>
                <a href="# ">合作伙伴</a>
                <a href="# ">联系我们</a>
                <a href="# ">网站地图</a>
                <em>© 2015-2025 Hengwang.com 版权所有. 更多模板 <a href="http://www.cssmoban.com/" target="_blank"
                                                           title="模板之家">模板之家</a> - Collect from <a
                        href="http://www.cssmoban.com/" title="网页模板" target="_blank">网页模板</a></em>
            </p>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $('#doc-my-tabs').tabs();
    });
    new Vue({
        el:"#app",
        data:{
            phoneReg:{              //手机验证码注册的表单绑定对象
                phone:'',           //手机号
                verifyCode:'',      //验证码
                password:'',        //密码
                confirmPassword:'', //确认密码
                agreement: false,    //勾选同意协议
                type:'phone_reg'    //手机号注册phone_reg   邮箱注册email_reg
            },
            emailReg:{              //邮箱注册的表单绑定对象
                email:'',           //邮箱
                password:'',        //密码
                confirmPassword:'', //确认密码
                agreement:false,    //勾选同意协议
                type:'email_reg'    //手机号注册phone_reg   邮箱注册email_reg
            },
            phoneValidateMsg:'' ,    //手机号验证消息
            PhoneValidateResult:false,
            emailValidateMsg:'',    //邮箱验证消息
            agreementValidateMsg:'', //勾选商城协议验证消息
            btnText:'获取',          //按钮上面的文字
            btnDisabled:false       //按钮是否禁用
        },
        methods:{
            //验证邮箱
            ValidEmail(){
                if(/^([a-zA-Z0-9]+[-_\.]?)+@[a-zA-Z0-9]+\.[a-z]+$/.test(this.emailReg.email)){
                    this.emailValidateMsg = '';
                    $('#email_reg').css("border","1px solid green");
                    return true;
                }
                this.emailValidateMsg = '邮箱格式错误！';
                $('#email_reg').css("border","1px solid red");
                return false;
            },
            //验证手机号
            validPhone(){
                if(!/^1[3-9][0-9]{9}$/.test(this.phoneReg.phone)){
                    this.phoneValidateMsg = '请输入正确的手机号！';
                    $('#phone_reg').css("border","1px solid red");
                    return false;
                }
                //发送请求去查询数据库，验证手机号是否被占用
                this.$http.get("/lr/validatePhone/phone_reg/"+this.phoneReg.phone)
                    .then(res => {
                        let {success,message} = res.data;
                        if (success){
                            this.phoneValidateMsg = '';
                            $('#phone_reg').css("border","1px solid green");
                            this.PhoneValidateResult =true;
                        }else {
                            this.phoneValidateMsg = message;
                            $('#phone_reg').css("border","1px solid red");
                            this.PhoneValidateResult =false;
                        }
                    });
                return this.PhoneValidateResult;
            },
            //验证勾选同意协议的多选矿
            validAgreement(){
                if(this.phoneReg.agreement || this.emailReg.agreement){
                    agreementValidateMsg:'';
                }else {
                    agreementValidateMsg:'请勾选商城协议！';
                }
                return this.phoneReg.agreement || this.emailReg.agreement;
            },
            //验证码不能为空
            validCode(){
                if (this.phoneReg.verifyCode){
                    return true;
                }
                return false;
            },
            //验证密码不为空
            validPassword(){
                if (this.phoneReg.password || this.emailReg.password){
                    return true;
                }
                return false;
            },
            //验证确认密码不为空且两次密码相同
            validConfirmPassword(){
                p=this.phoneReg.password;
                pp=this.phoneReg.confirmPassword;
                e = this.emailReg.password;
                ee=this.emailReg.confirmPassword;
                if((pp!=null & p==pp)||(ee!=null & e==ee)){
                    return true
                }
                return false;
            },
            //获取手机验证码
            sendMobileCode(){
                if(this.validPhone()){
                    this.btnDisabled =true;
                    let time =60;
                    this.btnText = time;
                    //开始倒计时：每个一分钟执行一次定时器
                    let intervalId = setInterval(()=>{
                        time--;
                        this.btnText = time;
                        if (time<=0){
                            clearInterval(intervalId);
                            this.btnDisabled = false;
                            this.btnText = '获取';
                        }
                    },1000);
                    this.$http.get("/lr/sendMobileCode/"+this.phoneReg.type+"/"+this.phoneReg.phone)
                        .then(res=>{
                            let {success,message} = res.data;
                            alert(message)
                        })
                }
                this.phoneValidateMsg = '请输入正确的手机号！';
                $('#phone_reg').css("border","1px solid red");
            },
            //提交注册表单
            submitReg(){
                if( this.validPhone() & this.validAgreement() & this.validCode() & this.validPassword() & this.validConfirmPassword()){
                    //提交表单
                    this.$http.put("/lr/phoneReg", this.phoneReg).then(res => {
                        let {success,message,data} = res.data
                        if(success){
                            localStorage.setItem("userToken",data.userToken);
                            localStorage.setItem("userJsonStr",data.userJsonStr);
                            location.href = '/index.html'
                        }else{
                            alert(message);
                        }
                    })
                }
            },
            emailSubmit(){
                if(this.ValidEmail() &this.validPassword() & this.validConfirmPassword() &this.validAgreement()){
                    //提交表单
                    this.$http.put("/lr/phoneReg", this.emailReg).then(res => {
                        console.debug(res);
                        alert("12");
                        let {success,message} = res.data;
                        /*if(success){
                            location.href = '/login.html'
                        }else{
                            alert(message);
                        }*/
                    })
                }
            }

        }
    })
</script>


</body>
</html>